Public Class ProjectList

    Private Const ConfirmationMessage As String = "You are about to delete {0} rows. This operation cannot be undone. Do you wish to continue?"

    Private Const ProjectIdColumnIndex As Integer = 0

    Private Sub ProjectList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.ListTableAdapter.Fill(Me.ProjectListData.List)

    End Sub

    Private Sub ProjectListView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ProjectListView.KeyDown

        If e.KeyCode = Keys.Delete Then
            e.SuppressKeyPress = True
        End If

    End Sub

    Private Sub DeleteSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteSelected.Click

        Try

            Dim ppdAdapter As New ProjectProductsDataTableAdapters.ProjectProductsTableAdapter
            Dim pmAdapter As New ProjectMaterialsDataTableAdapters.ProjectMaterialsTableAdapter
            Dim pAdapater As New ProjectsTableAdapters.ProjectTableAdapter

            Dim projectId As Integer = -1

            Dim response As DialogResult = MessageBox.Show(String.Format(ConfirmationMessage, ProjectListView.SelectedRows.Count), _
                                                           "Delete row(s)?", _
                                                               MessageBoxButtons.YesNo, _
                                                               MessageBoxIcon.Question, _
                                                               MessageBoxDefaultButton.Button2)
            If (response = DialogResult.Yes) Then
                For Each row As DataGridViewRow In ProjectListView.SelectedRows
                    projectId = CType(row.Cells(ProjectIdColumnIndex).Value, Integer)
                    ppdAdapter.DeleteForPorject(projectId)
                    pmAdapter.DeleteForProject(projectId)
                    pAdapater.Delete(projectId)
                Next
                ProjectListDS.EndEdit()
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            Me.ListTableAdapter.Fill(Me.ProjectListData.List)
        End Try

    End Sub

End Class